VERSION 5.00
Object = "{86CF1D34-0C5F-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCT2.OCX"
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "msflxgrd.ocx"
Begin VB.Form frmEstimatedExpYearly 
   BorderStyle     =   1  'Fixed Single
   ClientHeight    =   7425
   ClientLeft      =   3735
   ClientTop       =   2415
   ClientWidth     =   12960
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   ScaleHeight     =   7425
   ScaleWidth      =   12960
   Begin VB.Frame Frame1 
      Caption         =   "Detail"
      Height          =   2415
      Left            =   2040
      TabIndex        =   10
      Top             =   3360
      Width           =   4215
      Begin VB.ComboBox cboApplyYear 
         Height          =   315
         Left            =   1080
         TabIndex        =   46
         Top             =   1080
         Width           =   1215
      End
      Begin VB.ComboBox cboApplyMonth 
         Height          =   315
         Left            =   3240
         TabIndex        =   44
         Text            =   "ALL"
         Top             =   960
         Visible         =   0   'False
         Width           =   855
      End
      Begin VB.TextBox txtDescription 
         BeginProperty Font 
            Name            =   "VK Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   372
         Left            =   1080
         TabIndex        =   6
         Top             =   1920
         Width           =   3012
      End
      Begin VB.TextBox txtDoneBy 
         BeginProperty Font 
            Name            =   "VK Sans Serif"
            Size            =   9.75
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   372
         Left            =   1080
         TabIndex        =   5
         Top             =   1560
         Width           =   2055
      End
      Begin MSComCtl2.DTPicker DTPicker1 
         Height          =   375
         Left            =   1080
         TabIndex        =   19
         Top             =   600
         Width           =   2055
         _ExtentX        =   3625
         _ExtentY        =   661
         _Version        =   393216
         CustomFormat    =   "DD/MM/YYYY"
         Format          =   21168129
         CurrentDate     =   39574
         MaxDate         =   40543
         MinDate         =   36526
      End
      Begin VB.TextBox txtOff 
         Height          =   375
         Left            =   1080
         TabIndex        =   40
         Top             =   240
         Width           =   1575
      End
      Begin VB.TextBox txtOffice 
         Height          =   495
         Left            =   9120
         TabIndex        =   34
         Text            =   "hfuttfjnggggggggggggggggggggggggggggggggggggggggggggggggggggggg"
         Top             =   840
         Visible         =   0   'False
         Width           =   615
      End
      Begin VB.Label Label9 
         AutoSize        =   -1  'True
         Caption         =   "Apply year"
         Height          =   195
         Left            =   180
         TabIndex        =   45
         Top             =   1080
         Width           =   735
      End
      Begin VB.Label Label1 
         AutoSize        =   -1  'True
         Caption         =   "Office"
         Height          =   195
         Index           =   0
         Left            =   495
         TabIndex        =   39
         Top             =   360
         Width           =   420
      End
      Begin VB.Label Label8 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Note"
         Height          =   195
         Left            =   570
         TabIndex        =   13
         Top             =   2040
         Width           =   345
      End
      Begin VB.Label Label4 
         Alignment       =   1  'Right Justify
         AutoSize        =   -1  'True
         Caption         =   "Input by"
         Height          =   195
         Left            =   345
         TabIndex        =   12
         Top             =   1560
         Width           =   570
      End
      Begin VB.Label Label1 
         Alignment       =   1  'Right Justify
         Caption         =   "Date"
         Height          =   255
         Index           =   1
         Left            =   540
         TabIndex        =   11
         Top             =   720
         Width           =   375
      End
   End
   Begin VB.TextBox txtType 
      Height          =   375
      Left            =   6720
      TabIndex        =   36
      Top             =   120
      Visible         =   0   'False
      Width           =   3255
   End
   Begin VB.TextBox Text1 
      Appearance      =   0  'Flat
      BackColor       =   &H80000018&
      BorderStyle     =   0  'None
      Height          =   5175
      Left            =   0
      MousePointer    =   99  'Custom
      MultiLine       =   -1  'True
      TabIndex        =   33
      TabStop         =   0   'False
      Top             =   600
      Width           =   1935
   End
   Begin VB.CommandButton Command1 
      Caption         =   "Command1"
      Height          =   615
      Left            =   7560
      TabIndex        =   25
      Top             =   9480
      Visible         =   0   'False
      Width           =   1935
   End
   Begin VB.TextBox txtdate 
      Height          =   285
      Left            =   4080
      TabIndex        =   22
      Top             =   8640
      Visible         =   0   'False
      Width           =   975
   End
   Begin VB.TextBox txtSubID 
      Height          =   375
      Left            =   2040
      TabIndex        =   21
      Top             =   9000
      Visible         =   0   'False
      Width           =   735
   End
   Begin MSFlexGridLib.MSFlexGrid Grid1 
      Height          =   5175
      Left            =   6360
      TabIndex        =   17
      Top             =   600
      Width           =   6615
      _ExtentX        =   11668
      _ExtentY        =   9128
      _Version        =   393216
   End
   Begin VB.CommandButton cmdDone 
      Caption         =   "Close"
      Height          =   372
      Left            =   11280
      TabIndex        =   8
      Top             =   6480
      Width           =   972
   End
   Begin VB.CommandButton cmdSave 
      Caption         =   "Save"
      Height          =   372
      Left            =   7080
      TabIndex        =   7
      Top             =   6480
      Width           =   1332
   End
   Begin VB.Frame Frame2 
      Caption         =   "Control Panel"
      Height          =   855
      Left            =   840
      TabIndex        =   14
      Top             =   6120
      Width           =   12012
      Begin VB.CommandButton Command2 
         Caption         =   "Edit"
         Height          =   375
         Left            =   120
         TabIndex        =   43
         Top             =   360
         Width           =   1335
      End
      Begin VB.CommandButton cmdaddnew 
         Caption         =   "Add New"
         Height          =   375
         Left            =   3240
         TabIndex        =   18
         Top             =   360
         Width           =   1815
      End
      Begin VB.CommandButton cmdPreview 
         Caption         =   "Preview and Print"
         Height          =   372
         Left            =   7800
         TabIndex        =   16
         Top             =   1200
         Width           =   1812
      End
      Begin VB.CommandButton cmdDelete 
         Caption         =   "Delete"
         Height          =   372
         Left            =   1560
         TabIndex        =   15
         Top             =   360
         Width           =   1572
      End
   End
   Begin VB.CommandButton cmd 
      Caption         =   "+more"
      Height          =   252
      Left            =   5160
      TabIndex        =   9
      Top             =   4080
      Width           =   612
   End
   Begin VB.TextBox txtIDType 
      Height          =   375
      Left            =   2760
      TabIndex        =   23
      Text            =   "1"
      Top             =   3960
      Visible         =   0   'False
      Width           =   975
   End
   Begin VB.TextBox txtBillType 
      Height          =   372
      Left            =   5880
      TabIndex        =   24
      Text            =   "Unkow"
      Top             =   8520
      Visible         =   0   'False
      Width           =   1335
   End
   Begin VB.Frame Frame3 
      Height          =   2775
      Left            =   2040
      TabIndex        =   26
      Top             =   600
      Width           =   4215
      Begin VB.TextBox txtOwner 
         Height          =   375
         Left            =   1080
         TabIndex        =   3
         Top             =   1800
         Width           =   2535
      End
      Begin VB.TextBox txtDes 
         Height          =   375
         Left            =   1080
         TabIndex        =   2
         Top             =   1440
         Width           =   2535
      End
      Begin VB.TextBox txtValue 
         Height          =   372
         Left            =   1080
         TabIndex        =   1
         Top             =   1080
         Width           =   2175
      End
      Begin VB.CommandButton cmdAdd 
         Caption         =   "&Add"
         Height          =   375
         Left            =   3000
         TabIndex        =   4
         Top             =   2280
         Width           =   1095
      End
      Begin VB.CommandButton cmdRemove 
         Caption         =   "Remove"
         Height          =   375
         Left            =   2040
         TabIndex        =   29
         Top             =   2280
         Width           =   975
      End
      Begin VB.CommandButton cmdEdit 
         Caption         =   "Edit"
         Enabled         =   0   'False
         Height          =   375
         Left            =   1080
         TabIndex        =   30
         Top             =   2280
         Width           =   975
      End
      Begin VB.CommandButton cmdAddType 
         Caption         =   "..."
         Height          =   375
         Left            =   3360
         TabIndex        =   32
         Top             =   240
         Width           =   375
      End
      Begin VB.CommandButton cmdCancel 
         Caption         =   "Cancel"
         Enabled         =   0   'False
         Height          =   375
         Left            =   240
         TabIndex        =   31
         Top             =   2280
         Width           =   855
      End
      Begin VB.ComboBox cboType 
         Height          =   315
         ItemData        =   "frmEstimatedExpYearly.frx":0000
         Left            =   1080
         List            =   "frmEstimatedExpYearly.frx":0002
         TabIndex        =   0
         Top             =   240
         Width           =   2175
      End
      Begin VB.Label Label7 
         AutoSize        =   -1  'True
         Caption         =   "Item"
         Height          =   195
         Left            =   645
         TabIndex        =   42
         Top             =   720
         Width           =   300
      End
      Begin VB.Label lblItem 
         BackColor       =   &H00C0FFFF&
         BorderStyle     =   1  'Fixed Single
         Height          =   495
         Left            =   1080
         TabIndex        =   41
         Top             =   600
         Width           =   3015
      End
      Begin VB.Label Owner 
         AutoSize        =   -1  'True
         Caption         =   "Owner"
         Height          =   195
         Left            =   480
         TabIndex        =   38
         Top             =   1800
         Width           =   465
      End
      Begin VB.Label Label5 
         AutoSize        =   -1  'True
         Caption         =   "Description"
         Height          =   195
         Left            =   120
         TabIndex        =   37
         Top             =   1440
         Width           =   795
      End
      Begin VB.Label Label2 
         AutoSize        =   -1  'True
         Caption         =   "Total in USD"
         Height          =   195
         Left            =   30
         TabIndex        =   28
         Top             =   1080
         Width           =   915
      End
      Begin VB.Label Label3 
         AutoSize        =   -1  'True
         Caption         =   "Type"
         Height          =   195
         Left            =   585
         TabIndex        =   27
         Top             =   360
         Width           =   360
      End
   End
   Begin VB.Label Label10 
      AutoSize        =   -1  'True
      Caption         =   "Total estimated"
      Height          =   195
      Left            =   9360
      TabIndex        =   48
      Top             =   5880
      Width           =   1080
   End
   Begin VB.Label lblTotal 
      BackColor       =   &H00FF8080&
      BorderStyle     =   1  'Fixed Single
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H00FFFFFF&
      Height          =   375
      Left            =   10680
      TabIndex        =   47
      Top             =   5760
      Width           =   2175
   End
   Begin VB.Label lblTitle 
      AutoSize        =   -1  'True
      Caption         =   "Yearly Estimated expenditure"
      BeginProperty Font 
         Name            =   "MS Sans Serif"
         Size            =   18
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ForeColor       =   &H8000000D&
      Height          =   435
      Left            =   0
      TabIndex        =   20
      Top             =   0
      Width           =   5145
   End
   Begin VB.Label Label12 
      Caption         =   "Note on reasons for refusal"
      Height          =   255
      Left            =   0
      TabIndex        =   35
      Top             =   600
      Width           =   1935
   End
End
Attribute VB_Name = "frmEstimatedExpYearly"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Dim TinhTrang As String
Public N As Integer
Public Remember As Integer
Public EditOrAddnew As String
Public isSaved As Boolean
Private Function SetCommandStatus(whathappen As String)
    Select Case UCase(whathappen)
        Case "START"
                cmdRemove.Enabled = False
                cmdAdd.Enabled = True
                cmdAdd.Caption = "&Add"
                cmdEdit.Enabled = False
                EditOrAddnew = "addnew"
                cmdCancel.Enabled = False
        Case "RMT"
                cmdRemove.Enabled = False
                cmdAdd.Enabled = True
                cmdEdit.Enabled = False
                cmdCancel.Enabled = False
                EditOrAddnew = "addnew"
                cmdAdd.Caption = "Add"
        Case "ADD"
                cmdRemove.Enabled = False
                cmdAdd.Enabled = True
                cmdEdit.Enabled = False
                cmdCancel.Enabled = False
                EditOrAddnew = "addnew"
        Case "EDIT"
                cmdRemove.Enabled = False
                cmdAdd.Enabled = True
                cmdAdd.Caption = "Save"
                cmdEdit.Enabled = False
                cmdCancel.Enabled = True
                EditOrAddnew = "edit"
        Case "REMOVEEDIT"
                cmdRemove.Enabled = True
                cmdAdd.Enabled = False
                cmdAdd.Caption = "Add"
                cmdEdit.Enabled = True
                cmdCancel.Enabled = True
        Case Else
            MsgBox "Sorry, I do not know what are you doing!", vbCritical + vbOKOnly, "Set command status message"
            End
    End Select
    
End Function

Public Function SetCommandStatusForDetail(whathappen As String)
    Select Case UCase(whathappen)
        Case "START"
                cmdDelete.Enabled = False
                cmdaddnew.Enabled = False
                'cmdPreview.Enabled = False
                cmdSave.Enabled = True
                isSaved = False
        Case "DELEDITADDPREVIEW"
                cmdDelete.Enabled = True
                cmdaddnew.Enabled = True
                'cmdPreview.Enabled = True
                cmdSave.Enabled = True
                cmdSave.Caption = "Save edit"
                isSaved = False
        Case "ADD"
                cmdDelete.Enabled = False
                cmdaddnew.Enabled = False
                'cmdPreview.Enabled = False
                cmdSave.Enabled = True
                cmdSave.Caption = "Save"
                isSaved = False
        Case "SAVED"
                cmdDelete.Enabled = True
                cmdaddnew.Enabled = True
               ' cmdPreview.Enabled = True
                cmdSave.Caption = "Save"
                cmdSave.Enabled = False
                isSaved = True
        Case Else
            MsgBox "Sorry, I do not know what are you doing!", vbCritical + vbOKOnly, "Set command status message"
            End
    End Select
    
End Function

 

Private Sub cboFrom_Click()
'txtType.Text = UCase(cboType.Text & cboFrom.Text & cboTo.Text)
End Sub

Private Sub cboTo_Click()
'txtType.Text = UCase(cboType.Text & cboFrom.Text & cboTo.Text)
End Sub

Private Sub cboType_Change()
txtType.Text = UCase(cboType.Text)
End Sub

Private Sub cboType_Click()
'txtType.Text = UCase(cboType.Text & cboFrom.Text & cboTo.Text)
lblItem.Caption = GetItemType(cboType.Text)
End Sub

Private Sub cboType_LostFocus()
Dim strmssg As String
If txtBillType.Text <> "IV" Then
    Exit Sub
End If
strmssg = isTypeCorrect(cboType.Text)
If Len(strmssg) > 0 Then
    MsgBox strmssg, vbInformation + vbOKOnly, "Wrong message"
End If
End Sub





Private Sub cmdaddnew_Click()
SetCommandStatusForDetail ("ADD")
SetCommandStatus ("ADD")
 Call clearTextbox
 Call clearTextboxDetailFrame
 Call Format
 Grid1.rows = 2
 N = 0
 isSaved = False
 'Call DTPicker1_Change
 'cmbOFFC.SetFocus
End Sub

Private Sub cmdAddType_Click()
frmSelectType.BilltypeParameter = "ESTIMATED"
frmSelectType.isSelect = True
frmSelectType.Show
End Sub



Private Sub cmdCancel_Click()
    Call clearTextbox
    SetCommandStatus ("add")
End Sub

 

Private Sub cmdDel_Click()
If N >= 1 Then
    Remember = Grid1.Row
    If MsgBox("Are you sure you want to delete this data?", vbYesNo + vbQuestion, "Delete confirm?") = vbYes Then
        Grid1.rows = Grid1.rows + 1
        Grid1.RemoveItem (Remember)
        N = N - 1
        Grid1.rows = Grid1.rows - 1
    Else
        Exit Sub
    End If
    Call clearTextbox
   ' txtTotalNumber = Sum_Number()
    'cmdDel.Enabled = False
    cmdEdit.Enabled = False
Else
    MsgBox "There is nothing to delete!", vbOKOnly, "Delete message"
    'cmdDel.Enabled = False
    Exit Sub
End If
If N < 1 Then
   ' txtTotalNumber = ""
   ' txtTotalWords = ""
End If
End Sub

Private Sub cmdDelete_Click()
Dim subid As Integer
If Trim(cboApplyMonth.Text) = "" Or Trim(cboApplyYear.Text) = "" Then
    MsgBox "There is nothing to delete!", vbInformation + vbOKOnly, "Delete message"
    Exit Sub
End If

If MsgBox("Are you sure you want to delete this data?", vbInformation + vbYesNo, "Delete confirm") = vbNo Then
    Exit Sub
Else
    If EstimatedRemoveItem(cboApplyMonth.Text, cboApplyYear.Text, txtOff.Text) = False Then
        MsgBox "Error: System can not delete this data", vbCritical + vbOKOnly, "Delete error"
        Exit Sub
    End If
End If
SetCommandStatusForDetail ("ADD")
SetCommandStatus ("ADD")
 Call clearTextbox
 Call clearTextboxDetailFrame
 Call Format
 Grid1.rows = 2
End Sub



Private Sub cmdDone_Click()
If cmdSave.Enabled = False Or cmdSave.Visible = False Then
    Unload Me
    Exit Sub
    
End If
If isSaved Then
Unload Me
Exit Sub
End If
'If txtDoneBy.Text = "" And txtReceiver.Text = "" And txtCompanyTitle = "" And txtDescription.Text = "" And txtDocument.Text = "" Then
'    Unload Me
'    Exit Sub
'End If
    If MsgBox("Do you want to save this one?", vbYesNo + vbQuestion, "Save message") = vbYes Then
        Call cmdSave_Click
    Else
        Unload Me
        Exit Sub
    End If
If cmdSave.Enabled = False Then
    Unload Me
    Exit Sub
End If
Call cmdSave_Click
Unload Me
'   Unload Me
End Sub
Private Sub cmdEdit_Click()
    EditOrAddnew = "Edit"
    Remember = Grid1.Row
    SetCommandStatus ("edit")

        
End Sub

Private Sub cmdAdd_Click()
Dim sqldetail As String
Dim strmssg As String
 
    If Trim(cboType.Text) = "" Or Trim(txtValue.Text) = "" Or Trim(txtOwner.Text) = "" Then
        MsgBox "Please input into all white box", vbCritical + vbOKOnly, "Checking"
        Exit Sub
    End If

If Grid1.rows <= 1 Then
Grid1.rows = 2
N = 0
End If
Grid1.Row = 1
Grid1.Col = 2


sqldetail = Grid1.Text

    Select Case UCase(EditOrAddnew)
        Case "EDIT"
            If MsgBox("Are you sure you want to edit this data?", vbYesNo + vbQuestion, "Edit confirm") = vbYes Then
                If CheckTextHeaders = True Then
                    Grid1.Row = Remember
                    Grid1.Col = 1
                    Grid1.Text = Trim(cboType.Text)
                    Grid1.Col = 2
                    Grid1.Text = lblItem.Caption
                    Grid1.Col = 3
                    Grid1.Text = txtValue.Text
                    Grid1.Col = 4
                    Grid1.Text = txtOwner.Text
                    Grid1.Col = 5
                    Grid1.Text = txtDes.Text
                     
                Else
                    Exit Sub
                End If
            Else
                Exit Sub
            End If
        Case "ADDNEW"
            If CheckTextHeaders = True Then
                Grid1.rows = N + 2
                Grid1.Row = N + 1
                Grid1.Col = 0
                Grid1.Text = N + 1
                Grid1.Col = 1
                    Grid1.Text = Trim(cboType.Text)
                    Grid1.Col = 2
                    Grid1.Text = lblItem.Caption
                    Grid1.Col = 3
                    Grid1.Text = txtValue.Text
                    Grid1.Col = 4
                    Grid1.Text = txtOwner.Text
                    Grid1.Col = 5
                    Grid1.Text = txtDes.Text
                N = N + 1
      
            Else
                Exit Sub
            End If

        End Select
   
    lblTotal.Caption = FormatNumber(Sum_Number, 1) & "$"
    Call clearTextbox
     
End Sub

Private Sub cmdPreview_Click()
frmPrintPreview.Show
frmPrintPreview.setTitle (GetBillTypeDescription(Me.txtBillType.Text))
End Sub



Private Sub cmdRemove_Click()

If N >= 0 Then
    Remember = Grid1.Row
    If MsgBox("Are you sure you want to remove this data?", vbYesNo + vbQuestion, "Remove confirm") = vbYes Then
        Grid1.rows = Grid1.rows + 1
        Grid1.RemoveItem (Remember)
        N = N - 1
        Grid1.rows = Grid1.rows - 1
    Else
        Exit Sub
    End If
    Call clearTextbox
    ' txtTotalNumber = Sum_Number()
    
Else
    MsgBox "There is nothing to remove!", vbCritical + vbOKOnly, "Error"
    SetCommandStatus ("add")
    Exit Sub
End If
If N < 1 Then
   ' txtTotalNumber = ""
    'txtTotalWords = ""
End If
SetCommandStatus ("RMT")
End Sub

Private Sub cmdSave_Click()
    Grid1.Col = 1
 If Grid1.Text = "" Then
    MsgBox "The estimated detail can not be empty, Please reenter to the header", vbOKOnly + vbInformation, "Input check"
    Exit Sub
 End If
 If Grid1.rows <= 1 Then
 CheckTextHeaders
 Exit Sub
 End If
    If cmdSave.Caption = "Save edit" Then
        Call EstimatedRemoveItem(cboApplyMonth.Text, cboApplyYear.Text, txtOff.Text)
    End If
 
    Dim i, j, N As Integer
    Dim id As Integer
    Dim sqldetail As String
    Dim sqlheaders As String
    



        Dim sql As String
        If EstimatedExist(cboApplyMonth.Text, cboApplyYear.Text, txtOff.Text) Then
            If MsgBox("This estimated expenditure is already exist, do you want to save overwrite it? Y/N", vbQuestion + vbYesNo, "Accounting") = vbNo Then
                Exit Sub
            Else
                 Call EstimatedRemoveItem(cboApplyMonth.Text, cboApplyYear.Text, txtOff.Text)
            End If
        End If
        sql = "INSERT INTO estimated(office, esdate, esmonth, esyear, esapplymonth, esapplyyear, esinputby, esnote) VALUES('" & txtOff.Text & "','" & DTPicker1.Day & "','" & DTPicker1.Month & "','" & DTPicker1.Year & "','" & cboApplyMonth.Text & "','" & cboApplyYear.Text & "','" & txtDoneBy.Text & "','" & txtDescription.Text & "')"
        adoConnection.Execute sql

    
        N = Grid1.rows - 1
        For i = 1 To N
                sqlheaders = "INSERT INTO esheaders(esapplymonth, esapplyyear, office, esitem, esvalue, esowner, esdes) VALUES('" & cboApplyMonth.Text & "','" & cboApplyYear.Text & "','" & txtOff.Text & "'"
                Grid1.Row = i
                Grid1.Col = 1
                sqlheaders = sqlheaders & ",'" & Grid1.Text & "'"
                For j = 3 To 5
                    Grid1.Col = j
                    sqlheaders = sqlheaders & ",'" & Grid1.Text & "'"
                Next j
                sqlheaders = sqlheaders & ")"
                adoConnection.Execute sqlheaders
                
        Next i

SetCommandStatusForDetail ("SAVED")
 
End Sub



Private Sub clearTextbox()
   ' cmbOFFC.Text = ""
    txtValue.Text = ""
    'cboType.Text = ""
    cboType.Text = ""
    txtDes.Text = ""
    lblItem.Caption = ""
End Sub

Private Sub clearTextboxDetailFrame()
cboApplyMonth.Text = ""
cboApplyYear.Text = ""
txtDoneBy.Text = ""
txtDescription.Text = ""
Call clearTextbox
Grid1.Clear
Grid1.rows = 2

End Sub

Private Sub Command1_Click()
frmPrintPreview.Show
frmPrintPreview.setTitle (GetBillTypeDescription(Me.txtBillType.Text))
End Sub

Private Sub Command2_Click()
frmSelectEstimatedYear.Show
End Sub

Private Sub Command3_Click()

End Sub

Private Sub Form_Load()
Dim i As Integer
Me.Top = Screen.Height / 2 - (Me.Height / 1.5)
    Me.Left = Screen.Width / 2 - (Me.Width / 2)
'     For i = 1 To 9
'        cboApplyMonth.AddItem "0" & i
'
'        If Val(i) = Month(Now()) Then
'            cboApplyMonth.ListIndex = i - 1
'        End If
'    Next
'    For i = 10 To 12
'        cboApplyMonth.AddItem i
'        If Val(i) = Month(Now()) Then
'            cboApplyMonth.ListIndex = i - 1
'        End If
'    Next
    For i = 2008 To Year(Now()) + 1
        cboApplyYear.AddItem i
    Next
    cboApplyYear.Text = Year(Now())
     
    
    Call KetNoi
    Call Format
    Call SetCommandStatus("start")
    Grid1.rows = 2
    DTPicker1.Value = Now()
    DTPicker1.Format = dtpCustom
    DTPicker1.CustomFormat = "dd/MMM/yyyy"
    'Call SetOffcValue(cmbOFFC, txtBillType.Text)
    EditOrAddnew = "addnew"
    SetCommandStatusForDetail ("start")
    'Call filledindata(3)
    'SetCommandStatusForDetail ("DELEDITADDPREVIEW")
    'Call SetTypeValue(cboType, txtBillType.Text)
    
'    If permit <> "A" Then
'        Command2.Enabled = False
'
'    ElseIf permit = "A" Then
'        Command2.Enabled = True
'
'    End If
'
'    If permit = "B" Or permit = "G" Then
'        cmdSave.Visible = False
'        cmdDelete.Visible = False
'        cmdAdd.Visible = False
'        cmdBMApprove.Visible = True
'        cmdRefuse.Visible = False
'    Else
'         cmdBMApprove.Visible = False
'         cmdRefuse.Visible = False
'    End If
    N = 0
    Call SetTypeValue(cboType, "IV")
    txtOff.Text = "G" & stroffice
    'cmbOFFC.Style = 2
End Sub


Public Function filledindata(esmonth As String, esyear As String, Office As String)
Dim sql As String
Dim i As Integer
Dim id As Integer
Dim rs As New ADODB.Recordset
 
sql = "select * from estimated where office ='" & Office & "' and esapplymonth ='" & esmonth & "' and esapplyyear='" & esyear & "'"
Set rs = adoConnection.Execute(sql)

If Not rs.EOF Then
    txtOff.Text = rs.Fields("office").Value
    
    DTPicker1.Year = rs.Fields("esyear").Value
    DTPicker1.Month = rs.Fields("esmonth").Value
    DTPicker1.Day = rs.Fields("esdate").Value
    cboApplyMonth.Text = rs.Fields("esapplymonth").Value
    cboApplyYear.Text = rs.Fields("esapplyyear").Value
    
    txtDoneBy.Text = rs.Fields("esinputby").Value
    txtDescription.Text = GetFieldValue(rs.Fields("esnote"))
    
Else
    MsgBox "There is no data", vbInformation + vbOKOnly, "Accounting"
End If
If permit = "B" Or permit = "G" Then
            cmdaddnew.Visible = False
             
End If
rs.Close
i = 1
Grid1.rows = 1

sql = "select *  from esheaders where office ='" & Office & "' and esapplymonth ='" & esmonth & "' and esapplyyear='" & esyear & "'"

Set rs = adoConnection.Execute(sql)

While Not rs.EOF
        Grid1.AddItem ""
        Grid1.TextMatrix(i, 0) = i
        Grid1.TextMatrix(i, 1) = rs.Fields("esitem").Value
        Grid1.TextMatrix(i, 2) = GetItemType(rs.Fields("esitem").Value)
        Grid1.TextMatrix(i, 3) = rs.Fields("esvalue").Value
        Grid1.TextMatrix(i, 4) = rs.Fields("esowner").Value
        Grid1.TextMatrix(i, 5) = GetFieldValue(rs.Fields("esdes"))
         
        i = i + 1
    rs.MoveNext
Wend
'rs.MoveFirst
  lblTotal.Caption = FormatNumber(Sum_Number, 1) & "$"
rs.Close
Set rs = Nothing
SetCommandStatusForDetail ("DELEDITADDPREVIEW")
End Function
 

Private Function getDes(lvv As ListItem) As String
On Error GoTo L
getDes = lvv.SubItems(5)
Exit Function
L:
getDes = ""
Exit Function
End Function

Private Sub Grid1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Dim temp As String
Dim i As Integer
If Grid1.rows <= 1 Then
    Exit Sub
End If
temp = Grid1.TextMatrix(Grid1.MouseRow, 1)
 
If Trim(temp) <> "" Then
    If Len(temp) >= 5 Then
    temp = Left(temp, 5)
    Grid1.ToolTipText = GetTypeDescription(temp)
    End If
End If
End Sub

Private Sub Text1_Click()
Shell "C:\Program Files\Internet Explorer\IEXPLORE.EXE" & Space(1) & App.Path & "\help\help.htm", vbNormalFocus
End Sub

Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, x As Single, Y As Single)
Text1.MouseIcon = LoadPicture(App.Path & "\cur\" & "GBjabber_500.cur")
End Sub

Public Sub Format()
    Grid1.Clear
    Grid1.rows = 100
    Grid1.cols = 6
    Grid1.TextMatrix(0, 0) = "ORDER"
    Grid1.TextMatrix(0, 1) = "ID"
    Grid1.TextMatrix(0, 2) = "ITEMS"
    Grid1.TextMatrix(0, 3) = "TOTAL IN USD"
    Grid1.TextMatrix(0, 4) = "OWNER"
    Grid1.TextMatrix(0, 5) = "DES"
    Grid1.ColWidth(0) = 700
    Grid1.ColWidth(1) = 1000
    Grid1.ColWidth(2) = 2000
    Grid1.ColWidth(3) = 1200
    Grid1.ColWidth(4) = 1000
    Grid1.ColWidth(5) = 2000
End Sub
Private Sub Grid1_SelChange()
    'Call Control_Txt(False)
      SetCommandStatus ("REMOVEEDIT")
If (Grid1.rows > 1) Then
    cboType.Text = Grid1.TextMatrix(Grid1.Row, 1)
    txtValue.Text = Grid1.TextMatrix(Grid1.Row, 3)
    txtOwner.Text = Grid1.TextMatrix(Grid1.Row, 4)
    txtDes.Text = Grid1.TextMatrix(Grid1.Row, 5)
 
End If
 
End Sub
Private Function CheckTextHeaders() As Boolean
    Dim strr As String
    Dim CheckValue As Integer
    strr = ""
    If cboType.Text = "" Then
        strr = strr & "The type box must be filled in"
    End If
 
    
    If Trim(txtValue.Text) = "" Then
        CheckValue = 1
        strr = strr & Chr(13) & "The value box must be filled in"
    ElseIf Not IsNumeric(txtValue.Text) Then
        CheckValue = 1
        strr = strr & Chr(13) & "The value in 'Value box' must be number"
    End If
    
    If txtOwner.Text = "" Then
        strr = strr & Chr(13) & "The Owner box must be filled in"
    End If
   
    If strr <> "" Then
        MsgBox strr, vbInformation + vbOKOnly, "Checking"
        CheckTextHeaders = False
    Else
        CheckTextHeaders = True
    End If
End Function
Private Function CheckTextDetail() As Boolean
    Dim strr As String
    Dim check As Integer
    strr = ""
    If txtDoneBy.Text = "" Then
        strr = strr & "Reenter a valid data in Done by box"
    End If
    
    If txtDescription.Text = "" Then
        strr = strr & Chr(13) & "Reenter a valid data in Description box"
    End If
   
    If strr <> "" Then
        MsgBox strr
        CheckTextDetail = False
    Else
        CheckTextDetail = True
    End If
End Function
Private Function Sum_Number() As Variant
    Dim j, i As Integer
    Dim Tong As Variant
    Tong = 0
    i = Grid1.rows - 1
    Grid1.Col = 3
    For j = 1 To i
        Grid1.Row = j
        Tong = Tong + Val(Grid1.Text)
        Next j
        
Sum_Number = Tong
End Function



